#include "revise.h"
#include "ui_revise.h"
#include "studentstore.h"
#include <QString>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <string.h>
#include <QMessageBox>
#include <QTextCodec>
#include "login.h"
#include "importstudent.h"
#include "show_stuinfo.h"
#include "debug.h"
#include "test.h"
#include "utils.h"
using namespace std;
using namespace student;
using namespace studentstore;
using namespace utils;
revise::revise(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::revise)
{


    ui->setupUi(this);
}

revise::~revise()
{
    delete ui;
    delete thisstu;
}
//修改文件
void revise::on_pushButton_clicked()
{
    QString str = ui->lineEdit_2->text();
    string stu_id = string((const char *)str.toLocal8Bit());
    if(thisstu->stu_id[0]=='#'){
        ui->pushButton->setEnabled(false);ui->pushButton->hide();
        QMessageBox::warning(this,"warning","不能修改管理员信息");
    }
    else
    {
        if(!judge_user(stu_id))
            QMessageBox::warning(this,"warning","账号格式有误");
        QString str2 = ui->lineEdit->text();
        string name = string((const char *)str2.toLocal8Bit());
        if(name.length()>20)
            QMessageBox::warning(this,"warning","姓名长度需要小于20字节");
        Student* stu = new Student ();
        if(strcmp(name.c_str(),thisstu->name)==0&&
                strcmp(stu_id.c_str(),thisstu->stu_id)==0
                )
            QMessageBox::warning(this,"warning","并未作出修改");
        else
        {
            Student *stu = new Student ();
            stu=thisstu;
            strcpy(stu->name, &name[0]);
            strcpy(stu->stu_id, &stu_id[0]);

            rewrite(stu->ID,stu,studentDatPath);
            QMessageBox::information(this,"info","修改成功");
        }
        delete stu;
    }
}
void revise::getData(Student *stu)
{
    thisstu=stu;
    QString ID = QString(QString::number(stu->ID));
    ui->label->setText(ID);
    QString stu_name=str2Qstr(stu->name);
    ui->lineEdit->setText(stu_name);
    QString stu_id=str2Qstr(stu->stu_id);
    ui->lineEdit_2->setText(stu_id);
    stringList.clear();

}
